package cn.yusei.teamTribe.controller.post;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.yusei.teamTribe.constant.ResponseCode;
import cn.yusei.teamTribe.service.post.PostReflectService;
import cn.yusei.teamTribe.util.ResponseUtil;

@Controller
public class PostReflectionController {

	@Autowired
	private PostReflectService postReflectService;
	
	@RequestMapping(value="/post/getUser")
	public void getUser(@RequestParam int id, PrintWriter out)
	{
		if(id <= 0)
		{
			ResponseUtil.responseCode(out, ResponseCode.PARAM_ILLEGAL);
			return;
		}
		int userId = 0;
		try
		{
			userId = postReflectService.getUserId(id);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			ResponseUtil.responseCode(out, ResponseCode.SERVER_ERROR);
			return;
		}
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id", userId);
		ResponseUtil.response(out, ResponseCode.REQUEST_SUCCESSED, param);
	}
	
	@RequestMapping(value="/post/getTeam")
	public void getTeam(@RequestParam int id, PrintWriter out)
	{
		if(id <= 0)
		{
			ResponseUtil.responseCode(out, ResponseCode.PARAM_ILLEGAL);
			return;
		}
		int teamId = 0;
		try
		{
			teamId = postReflectService.getTeamId(id);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			ResponseUtil.responseCode(out, ResponseCode.SERVER_ERROR);
			return;
		}
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("id", teamId);
		ResponseUtil.response(out, ResponseCode.REQUEST_SUCCESSED, param);
	}
	
}
